package com.funtonow.jqdk.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * @author Jiajien
 * @date 2019/6/21
 */
public class TimeUtils {

    public static String dateToString(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        return sdf.format(date);
    }

    public static String dateToString(long date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        return sdf.format(date);
    }

    /**
     * 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
     *
     * @param strDate
     * @return
     */
    public static String longToString(long strDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        return formatter.format(new Date(strDate));
    }

    /**
     * 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
     *
     * @param strDate
     * @return
     */
    public static String longToTime(long strDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        return formatter.format(new Date(strDate));
    }

    /**
     * 是否显示dialog
     *
     * @return
     */
    public static boolean isShowDialog() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        Date date = new Date(System.currentTimeMillis());
        String nowTime = (String) SPUtil.get("isShow", "");
        if (StringUtil.isEmpty(nowTime)) {
            SPUtil.put("isShow", simpleDateFormat.format(date));
            return true;
        } else {
            if (nowTime.equals(simpleDateFormat.format(date))) {
                return false;
            } else {
                SPUtil.put("isShow", simpleDateFormat.format(date));
                return true;
            }
        }
    }

    /**
     * 是否显示红点
     * @return
     */
    public static boolean isShowHot() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        Date date = new Date(System.currentTimeMillis());
        String nowTime = (String) SPUtil.get("isShowHot", "");
        if (StringUtil.isEmpty(nowTime)) {
            SPUtil.put("isShowHot", simpleDateFormat.format(date));
            return true;
        } else {
            if (nowTime.equals(simpleDateFormat.format(date))) {
                return false;
            } else {
                SPUtil.put("isShowHot", simpleDateFormat.format(date));
                return true;
            }
        }
    }


    /**
     * 是否显示红点
     * @return
     */
    public static boolean isShowNewsHot() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        Date date = new Date(System.currentTimeMillis());
        String nowTime = (String) SPUtil.get("isShowNewsHot", "");
        if (StringUtil.isEmpty(nowTime)) {
            SPUtil.put("isShowNewsHot", simpleDateFormat.format(date));
            return true;
        } else {
            if (nowTime.equals(simpleDateFormat.format(date))) {
                return false;
            } else {
                SPUtil.put("isShowNewsHot", simpleDateFormat.format(date));
                return true;
            }
        }
    }

    /**
     * 今天是否点击设置资料
     */
    public static boolean isShowUserInfo() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        Date date = new Date(System.currentTimeMillis());
        String nowTime = (String) SPUtil.get("isShowInfo", "");
        if (!StringUtil.isEmpty(nowTime) && nowTime.equals(simpleDateFormat.format(date))) {
            return false;
        } else {
            return true;
        }
    }

    public static String nowTime() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        Date date = new Date(System.currentTimeMillis());
        return simpleDateFormat.format(date);
    }

}
